<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="card-title">
        <span>匹配结果</span>
      </div>
      <div class="loanApprove-box">
        <!-- 日期选择器的容器 -->
        <div class="date-box">
          <span>日期选择</span>
          <el-date-picker
            style="margin-left: 20px"
            v-model="dateRange"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions"
            @change="OnDateChange"
          >
          </el-date-picker>
          <el-button type="success" style="margin-left: 15px" @click="onSearch"
            >查询</el-button
          >
        </div>
      </div>
      <el-table
        :data="tableData"
        :header-cell-style="{ background: '#e1e4e5' }"
        stripe
        style="width: 100%"
        class="table"
      >
        <el-table-column prop="transNo" label="匹配流水号"> </el-table-column>
        <el-table-column prop="userId" label="投资人编号"> </el-table-column>
        <el-table-column prop="debtId" label="投资编号"> </el-table-column>
        <el-table-column prop="investId" label="债权编号"> </el-table-column>
        <el-table-column prop="Money" label="匹配金额"> </el-table-column>
        <el-table-column prop="matchDate" label="匹配时间"> </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="prev, pager, next"
        class="pagination"
        @current-change="onPageChange"
        :page-count="filterData.totalPages"
        :current-page="filterData.curPage"
        :page-size="filterData.perPage"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      filterData: {
        // 日期开始时间
        start: "",
        // 日期结束时间
        end: "",
        // 总页数
        totalPages: 1,
        // 当前页
        curPage: 1,
        // 每页显示几条数据
        perPage: 3,
      },
      // 表格数据
      tableData: [],
      // 日期的数据
      dateRange: "",
    };
  },
  methods: {
    ...mapActions({
      getMatchedResult: "transaction/matchedResult",
    }),
    getMatchedResultList() {
      this.getMatchedResult(this.filterData).then((res) => {
        this.tableData = res.content;
        this.filterData.totalPages = res.paginateInfo.pages;
      });
    },
    // 点击查询的时候
    onSearch() {
        this.getMatchedResultList();
        this.filterData.curPage = 1
    },
    // 当日期选择器选择内容发送变化时
    OnDateChange(data) {
      if (data) {
        console.log("日期选择发生变化时", data);
        this.filterData.start = data[0];
        this.filterData.end = data[1];
      } else {
        this.filterData.start = "";
        this.filterData.end = "";
      }
    },
    // 点击页数的时候
    onPageChange(index) {
      this.filterData.curPage = index;
      this.getMatchedResultList();
    },
  },
  created() {
    this.getMatchedResultList();
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .box-card {
    .table {
      margin-top: 5px;
    }
    .pagination {
      margin-top: 5px;
    }
  }
}
</style>
